#include<iostream>
using namespace std;
#include<vector>
#include<algorithm>
/*
学习目标：
vector中存放自定义数据类型，并打印输出
*/
int haha()
{
    return 2;
}
void test(int i,int (*p)())
{
    cout<<p()<<i<<endl;
}
class Person
{
public:
    Person(string name,int age)
    {
        this->m_Name=name;
        this->m_Age=age;
    }
    string m_Name;
    int m_Age;
};
void myPrint(Person &p)
{
    cout<<"name="<<p.m_Name<<" age="<<p.m_Age<<endl;
}
void myPrint2(Person *&p)
{
    cout<<"name="<<p->m_Name<<" age="<<p->m_Age<<endl;
}
void test01()
{
    vector<Person> v;
    Person p1("陆博",12);
    Person p2("刘港",10);
    
    v.push_back(p1);
    v.push_back(p2);
    for(vector<Person>::iterator it=v.begin();it!=v.end();it++)
    {
        cout<<"name="<<(*it).m_Name<<" age="<<it->m_Age<<endl;
    }
    for_each(v.begin(),v.end(),myPrint);
}
//存放自定义类型 指针
void test02()
{
    vector<Person*> v;
    Person p1("陆博",12);
    Person p2("刘港",10);
    
    v.push_back(&p1);
    v.push_back(&p2);

    for(vector<Person*>::iterator it=v.begin();it!=v.end();it++)
    {
        cout<<"name="<<(*it)->m_Name<<" age="<<(*it)->m_Age<<endl;
    }
    for_each(v.begin(),v.end(),myPrint2);
}
int main()
{
    test01();
    test(3,haha);
    test02();
}